﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.EntityValidation
{
    public class InEnumAttribute : ValidationAttribute
    {

        public InEnumAttribute()
        {
            ErrorMessage = "{0}应该在区间内";
        }
        public Type RangeType { get; set; }
        public override bool Verify(object o)
        {

            if (o == null)
            {
                return false;
            }
            var r = false;
            foreach (var item in Enum.GetValues(RangeType))
            {
                if (((int)item) == Convert.ToInt32(o))
                {
                    r = true;
                    break;
                }
            }
            return r;
        }
    }
}